<?php

// Inialize session
session_start();

// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['username'])) {
        header('Location: index.php');
}

?>
<!-- BY BING HUA -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<title>
		Edit Rotation Plans
	</title>
	<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
	<meta name="keywords" content="" />
	<meta name="description" content="" />
	<link href="style.css" rel="stylesheet" type="text/css" media="screen" />

	<style type="text/css">
	</style> 
	
	<?php
	include 'functions.php';
	?>
</head>

<body>
	<?php
			include 'headinfo.php';
	?>
	<hr />
	<div id="header">
		<?php
			$thispage = "Administrative";
			require 'menu.php';
		?>
		<!-- end #menu -->
	</div>
	<!-- end #header -->
	<!-- end #header-wrapper -->
	<div id="page">
		<div id="content">
		  	<div class="post">
		  		
			  <h2 class="title"><a href="#">Administrative</a></h2>
							
				<p class="meta"></p>
				<?php
					$thissubpage ="Edit Rotation Plans";
					require 'menu_admin.php';
				?>
				
				<?php
    				if(isset($_POST['Successor'])){
		
    				$categoryone = $_POST ['categoryone'];
    				$categorytwo = $_POST ['categorytwo'];
    				if($categoryone!=="category"&&$categorytwo!=="category"&&$categoryone!==$categorytwo){
    					EditSuccessor(getCategoryId($categoryone), getCategoryId($categorytwo));
						
						echo '<META HTTP-EQUIV="Refresh" Content="0; URL=EditRotation.php">'; 
    					print($categoryone.'is followed by'.$categorytwo);
						
    				}else{
    				
    					print('please select two different categories');
    				}
    	
    				}
    	
    			?>
				
			<table class="tablecss">
			<br><br>
				<h2>Edit Rotation Plan</h2>			
			<td>
				<form name="form" method="post" action="EditRotation.php">
						<p>
							<span style="font-weight: bold;">Category </span>
							<select name="categoryone">
							<option value="Category">Select Category</option>
							<?php 
            					$allCategories = getAllCategories();
            					for($i = 0; $i<count($allCategories); $i++){
            						echo "<option value=\"".$allCategories[$i]['categoryname']."\">".$allCategories[$i]['categoryname']."</option>";
            					}
            				?>
							</select>
						<span style="font-weight: bold;">is followed by</span></p>
						
						<p>
							<span style="font-weight: bold;">Category </span>
							<select name="categorytwo">
							<option value="Category">Select Category</option>
							<?php 
            					$allCategoriestwo = getAllCategories();
            					for($i = 0; $i<count($allCategoriestwo); $i++){
            						echo "<option value=\"".$allCategoriestwo[$i]['categoryname']."\">".$allCategoriestwo[$i]['categoryname']."</option>";
            					}
            				?>
							</select>
						</p>
					</td>
					</tr>
					<tr>
					<td>
					
						
						<p align="center">
						    <input type="submit" name="Successor" id="Successor" value="OK" />
						</p>
					

					</form>
					</td>
					</tr>
					
					<table class="tablecss">
					<br><br>
					<h2>Rotation Plan</h2>					
					<?php 
						echo "<tr><th>Category</th><th>is followed by...</th></tr>\n";
						if ($result=getPrintCategory()) {
							while ($row=mysql_fetch_row($result)) {
								echo "<td>".$row[1]."</td>";
								if ($row[2]==""){
									echo "<td>"."-"."</td></tr>\n";
								} else {
									echo "<td>".getCategoryNameId($row[2])."</td></tr>\n";
								}
							}
						} else {
							echo "<!-- SQL Error ".mysql_error()." -->";
						}
						echo "</table>";
            			
						?>
						<!--$allCategories = getCategoryName();
            			for($i = 0; $i<count($allCategories); $i++){
            				echo "<tr><td>".$allCategories[$i]['categoryname']."</td></tr>";
            			}
            		?>
				
            		</table>
					-->
					
				

			</div>
		</div>
	</div>
	<div style="clear: both;">&nbsp;</div>
	
<div id="footer">
	<p>Copyright (c) 2010 Dilmun Hill Team.</p>
</div>
	
</body>

</html>